#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
}

Widget::~Widget()
{
   pTeacher = new Teacher(this);
   pStudent = new Student(this);
   //connect(pTeacher,&Teacher::hungry,pStudent,&Student::treat);

   //函数重载,解决方法：1.函数指针 2.static_cast

   //使用函数指针连接有参
   void (Teacher::*teacher_Qstring)(QString) = &Teacher::hungry;
   void (Student::*student_Qstring)(QString) = &Student::treat;

   connect(pTeacher,teacher_Qstring,pStudent,student_Qstring);

   //使用static_cast连接无参
  connect(pTeacher,
          static_cast<void (Teacher::*)()>(&Teacher::hungry),
          pStudent,
          static_cast<void (Student::*)()>(&Student::treat));
   this->ClassIsOver();
}

void Widget::ClassIsOver() 
{
    emit pTeacher->hungry();
    emit pTeacher->hungry("黄焖鸡");
}

